package com.liwenfeng.thread;

// 包子铺（生产者、消费者模式）
public class BaoZiPu {
    private int count;
    private boolean flag;

    public synchronized void consumer() throws InterruptedException {
        while (!flag) {
            this.wait();
        }
        flag = false;
        System.out.println("消费第 " + count + " 个包子");
        this.notifyAll();
    }

    public synchronized void product() throws InterruptedException {
        while (flag) {
            this.wait();
        }
        count++;
        flag = true;
        System.out.println("生产第==== " + count + " 个包子");
        this.notifyAll();
    }

}
